<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 * 
 * 创建时间：2021-08-28 15:23
 *
 * 项目：rm  -  $  - payIdenHelper.php
 *
 * 作者：liwei 
 */

namespace modules\levpays;

use Lev;
use lev\helpers\ScoreHelper;
use lev\helpers\SettingsHelper;
use modules\levpays\helpers\levpaysSetHelper;
use modules\levpays\table\tradesHelper;

!defined('INLEV') && exit('Access Denied LEV');

class payIdenHelper extends BasePayIden
{

    /**
     * @return array
     */
    public static function getPayGoodsInfo($uid, $goodsId, $paymoney, $tradeId, $extParam = []) {
        $goodses = levpaysSetHelper::goodsScores();
        if (empty($goodses[$goodsId])) {
            return [];
        }
        $ency  = 'CNY';
        $goods = [
            'lists'   => [],//eg: ['name'=>'','img'=>'','price'=>'']
            'goodsid' => $goodsId,
            'name'    => $goodses[$goodsId]['name'],
            'descs'   => $goodses[$goodsId]['descs'],
            'img'     => ScoreHelper::svgScoreIcon($goodses[$goodsId]['scoretype']),
            'paymoney'=> $goodses[$goodsId]['price'],
            'ency'    => $ency,
        ];
        empty($tradeId) && $tradeId = tradesHelper::createTradeId('levpays', $goodsId, $uid, $goods['paymoney'], $goods['name']);
        $goods['tradeId'] = $tradeId;
        $goods['tradeNo'] = tradesHelper::getTradeno($tradeId);
        return $goods;
    }

    public static function setPaySuccess($tradeInfo, $extParam = [])
    {
        $goodses = levpaysSetHelper::goodsScores();
        if (empty($goodses[$tradeInfo['goodsid']])) {
            return [];
        }
        $goods = $goodses[$tradeInfo['goodsid']];
        if (!empty(Lev::$app['isDiscuz'])) {
            $scoretypes = ScoreHelper::scoretypes();
            is_numeric($goods['scoretype']) && isset($scoretypes[$goods['scoretype']]) &&
            $ac = ScoreHelper::acscore($goods['scoreNum'], '积分充值', $goods['scoretype'], $tradeInfo['uid']);
        }
        !isset($ac) &&
        $ac = ScoreHelper::acscoreUses($goods['scoreNum'], '积分充值', $goods['scoretype'], $tradeInfo['uid']);
        Lev::setNotices('积分充值已到账', true);
        return true;
    }
}